<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
				
					<div class="caption">
						<span class="title">合同明细详情</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">合同名称</div>
						<div class="field">
							${prjContDetail.CONT_DETAIL_NM}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">主合同编号</div>
						<div class="field">
							${prjContDetail.CONT_DETAIL_NM}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">合同状态</div>
						<div class="field">
							${prjContDetail.CONT_DETAIL_STATUS_DES}
						</div>
					</div>
					<div class="fieldBox col_100" >
						<div class="label">合同备注</div>
						<div class="field">
							${prjContDetail.CONT_DETAIL_REMARK}
						</div>
					</div>
					<div class="fieldBox col_100" >
						<div class="label">合同附件</div>
						<div class="field">
							<div id="ligergrid_file1" class="sq-grid"></div>
						</div>
					</div>
					<div class="fieldBox col_100" >
						<div class="label">批量操作</div>
						<div class="field" >
							<span class="sq-button sq-button-round" onclick="batchDownload();">批量下载</span>
						</div>
					</div>
					<div class="fieldBox col_100" >
						<div class="label">风控意见</div>
						<div class="field" >
							<div id="optionGrid" class="sq-grid"></div>
						</div>
					</div>
					<div class="fieldBox col_100" >
						<div class="label">风控意见填写</div>
						<div class="field">
							<textarea name="contDetailOpinion" id="contDetailOpinion" rows="3" class="l-textarea" style="width:98%" ></textarea>
						</div>
					</div>
					<!-- 附件上传 -->
					<div class="fieldBox col_100" >
						<div class="label">风控审核</div>
						<div class="field">
							     <jsp:include page="../frCommFilesUpload.jsp" flush="true" >
									<jsp:param name="filePath" value="ref"/>
								 </jsp:include>
								 <c:if test="${operate=='audit'}">
									<div id="fileUpload1" class="upfileBoxs"></div>
									<span class="sq-button sq-button-hasicon" id="btnUpload1" onclick="ajaxFileUploadImg('uploads1',2)">
										<i class="sqBtnIco_9"></i>上传
									</span>
								</c:if>
						</div>
					</div>
					<!-- 附件显示 -->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
			            	<jsp:include page="../frCommFilesList.jsp" flush="true" ></jsp:include>
							<div id="ligergrid_file2" class="sq-grid"></div>
						</div>
					</div>
					<!-- 隐藏支付表主键、支付表号 -->
	                <div class="fieldBox col_100" style="display:none;">
	                    <div class="field">
	                         <!-- 上传文件使用：系统时间和当前登录人姓名 -->
	                         <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate}">
	                         <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm}">
	                         <input name="ffrom" id="ffrom" type="text" class="ui-textbox" value="${from}">
	                    </div>
	                </div>
	                	
	                <c:if test="${from=='riskControlManager'}"><!--start风控经办审核节点展示 -->
			              <div class="fieldBox col_33" >
							<div class="label">最终版</div>
							<!-- <div class="field">
								<input id="contDetailFinal"  name="contDetailFinal"  placeholder="--请选择--"  ltype="combobox">
							</div> -->
							<div class="field">
							     <%-- <jsp:include page="../frCommFilesUpload.jsp" flush="true" >
									<jsp:param name="filePath" value="ref"/>
								 </jsp:include> --%>
								<div id="fileUpload2" class="upfileBoxs"></div>
								<span class="sq-button sq-button-hasicon" id="btnUpload2" onclick="ajaxFileUploadImg('uploads2',3)">
									<i class="sqBtnIco_9"></i>上传
								</span>
							</div>
						</div>
		             </c:if><!--end风控经办审核节点展示 -->	
		             <!-- 附件显示 -->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
			            	<%-- <jsp:include page="../frCommFilesList.jsp" flush="true" ></jsp:include> --%>
							<div id="ligergrid_file3" class="sq-grid"></div>
						</div>
					</div>							
				</div>
				
				<div class="btnsBox">
					<c:if test="${operate=='audit'}">
						<c:if test="${from=='riskControlManager'}">
							<span id="saveBtn" class="sq-button sq-button-round" onclick="auditSave(3);">终审通过</span>
						</c:if>
						<c:if test="${from=='riskControl'}">
							<span id="saveBtn" class="sq-button sq-button-round" onclick="auditSave(2);">通过</span>
						</c:if>
						<span id="saveBtn" class="sq-button sq-button-round" onclick="auditSave(4);">驳回</span>
					</c:if>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		var ffrom=$('#ffrom').val();
		$(function() {
			var contDetailFinal = "${prjContDetail.CONT_DETAIL_FINAL}";
			
			$("#ligerForm").ligerForm({
				validate: true
			});
			
			//1、合同附件列表
	    	loadFilesLiger("htfj", 1, "${prjContDetail.ID }","no");
	    	//最终版附件列表
	    
			
	    	if(ffrom == "riskControlManager"){//风控总经理
		    	loadFilesLiger("zhb", 3, "${prjContDetail.ID }", "yes");
			}else{
			    loadFilesLiger("zhb", 3, "${prjContDetail.ID }", "no");
			}
    	
	    	//2、风控意见列表
			$("#optionGrid").ligerGrid({
				url:'<%=path%>/rfcont/fncPrjContAudit/selectPrjContOptionList.do?contDetailId=${prjContDetail.ID}',
				method:'get',
				columns:[
					{display:'意见', name: 'CONT_DETAIL_OPINION',render:function (rowdata, rowindex, value){
						var h="<span title='"+rowdata.CONT_DETAIL_OPINION+"'>"+rowdata.CONT_DETAIL_OPINION+"</span>";
						return h;
					}},
					{display:'时间', name: 'CRT_TM_'},
					{display:'工号', name: 'USR_NM'},
					{display:'姓名', name: 'USR.RL_NM'}
				],
				usePager: false,//是否有分页便签
				isScroll: true,//是否有滚动条
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'300',
				heightDiff:-2,
				checkbox:false,//列表是否有选择框
				rownumbers:true,//列表是否有行号
				onAfterShowData: function () {
					//$( ".gridTip").grid_ligerTip();
					//SetIframe_height ();
				},
				selectRowButtonOnly:true//复选框模式时，是否只允许点击复选框才能选择行
			});
	    	
			//3、风控审核附件列表
			<c:if test="${operate=='audit'}">
				loadFilesLiger("htfk", 2, "${prjContDetail.ID}","yes");
	    	</c:if>
	    	<c:if test="${operate !='audit'}">
	    		loadFilesLiger("htfk", 2, "${prjContDetail.ID}");
	    	</c:if>
	    	
			//4、最终版select
			/* $("#contDetailFinal").ligerComboBox({
					valueField: 'id',
					textField: 'fileNm'
			}); */
			
			
			
			
	    });
	
		
		
		function auditSave(contDetailStatus){
			var ligerForm = liger.get("ligerForm");
			//1.校验 风控意见
			if($.trim($("#contDetailOpinion").val()) == ""){
				$.ligerDialog.SQalert({content: "请填写风控意见",SQ_type: "warning"});
				return false;
			}
			//2.校验 最终版 
			if(ffrom == "riskControlManager"){//风控总经理
				var index=3;
				var ligerNm = "ligergrid_file"+index;
				var zui=liger.get(ligerNm);
				var zuiDate=zui.getData();
				/* if(contDetailStatus==3){//终审通过
					if(zuiDate==null||zuiDate==''){
						$.ligerDialog.SQalert({content: "请上传最终版",SQ_type: "warning"});
						return false;
					}
				} */
			}
			//保存最终版附件
		    saveFile3('${prjContDetail.ID}','操作成功!');
			//3.封装数据  提交后台
			var data = ligerForm.getData();//获取表单数据
			data["contDetailStatus"] = contDetailStatus;
		
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/rfcont/fncPrjContAudit/auditSave.do?contDetailId=${prjContDetail.ID}',
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						 saveFile('${prjContDetail.ID}','操作成功!');//风控审核附件文件
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				}
			});
		}
		
		
		//保存文件
		function saveFile(pkId,info){
			var docArray = JSON.stringify(getUploadResultParams(2));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        		//Remove_navTab();//关闭申请窗口
        	}else{
		        if(pkId){//主表ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "htfk"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 //清空上传文件缓存
								 clearUploadResultParams(2);
							 }
							 Remove_navTab();//关闭申请窗口
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		
		
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
    		}
		}
		//保存文件
		function saveFile3(pkId,info){
			var docArray = JSON.stringify(getUploadResultParams(3));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray ||docArray == '[]' ){
        		//无要上传的文件-直接结束
        		top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        		//Remove_navTab();//关闭申请窗口
        	}else{
		        if(pkId){//主表ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "zhb"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 //清空上传文件缓存
								 clearUploadResultParams(3);
							 }
							 //Remove_navTab();//关闭申请窗口
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		
		
		//批量下载
	    function batchDownload() {
	    	
	        var ligergrid_file1 = liger.get("ligergrid_file1").getSelectedRows();//合同附件列表
	        if(ligergrid_file1.length > 10) {
	        	$.ligerDialog.SQalert({content: "一次下载最多10个合同附件！",SQ_type: "error"});
	        	return;
	        }
			var ids = [];
			for (var i = 0; i < ligergrid_file1.length; i++) {
	            ids.push(ligergrid_file1[i].id);
			}
			
			var from = "${from}";
		 	if("riskControlManager"== from) {//风控总经理节点
				var ligergrid_file2 = liger.get("ligergrid_file2").getData();//风控审核附件列表
				for (var i = 0; i < ligergrid_file2.length; i++) {
		            ids.push(ligergrid_file2[i].id);
				}    
         	}
			
			
			var actoinURL = '<%=path%>/rfcont/fncPrjContAudit/batchDownload.do';
	    	var form = $("<form>");
	        $('body').append(form);
	        form.attr('style','display:none');
	        form.attr('target','');
	        form.attr('method','post');
	        form.attr('action',actoinURL);
	        var input = $('<input>');
	        input.attr('type','hidden');
	        input.attr('name','ids');
	        input.attr('value',JSON.stringify(ids));
	        form.append(input);
	        
	        
	        
	        var input = $('<input>');
	        input.attr('type','hidden');
	        input.attr('name','applyId');
	        input.attr('value','${applyId}');
	        form.append(input);
	        
	        var input = $('<input>');
	        input.attr('type','hidden');
	        input.attr('name','contDetailNm');
	        input.attr('value','${prjContDetail.CONT_DETAIL_NM}');
	        form.append(input);
	        
	        var input = $('<input>');
	        input.attr('type','hidden');
	        input.attr('name','from');
	        input.attr('value','${from}');
	        form.append(input);
	        
	        form.submit();
	    }
	    
	</script>
</body>
</html>